home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / text / print / VirtPrinters2.lha / screen_printer_source / render.c < prev    next >
C/C++ Source or Header  |  1993-06-27  |  6KB  |  193 lines

  1. /****************************************************************************
  2.  *
  3.  *        Screen_Printer driver.
  4.  */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/nodes.h>
  8. #include <exec/lists.h>
  9. #include <exec/memory.h>
  10. #include <devices/prtbase.h>
  11. #include <devices/printer.h>
  12. #include <intuition/screens.h>
  13.  
  14. #include <clib/exec_protos.h>
  15. #include <clib/intuition_protos.h>
  16.  
  17. extern struct Library *AbsExecBase;
  18. extern struct Library *IntuitionBase;
  19.  
  20. extern struct PrinterData *PD;
  21. extern struct PrinterExtendedData *PED;
  22. extern struct Screen *myScrnHandle;
  23.  
  24. extern void SetDensity(ULONG);
  25. extern void Transfer(struct PrtInfo *PInfo, UWORD y, BYTE *ptr, UWORD colors[]);
  26.  
  27. #define MAXCOLORBUFS 3
  28.  
  29. int OpenMyScrn(ULONG w, ULONG h);
  30. void Eject(void);
  31.  
  32.         UWORD BufSize, ColorSize;
  33.     long linesleft;
  34.         UBYTE *ptr, *planeptr[MAXCOLORBUFS];
  35.     UWORD colors[MAXCOLORBUFS];
  36.     BOOL color_on;
  37. int Render(long ct, long x, long y, long status)
  38. {
  39.         int i, err, total;
  40.  
  41.         err=PDERR_NOERR;
  42.         switch(status) {
  43.                 case 0 : /* Master Initialization */
  44.                         /*
  45.                                 ct      - pointer to IODRPReq structure.
  46.                                 x       - width of printed picture in pixels.
  47.                                 y       - height of printed picture in pixels.
  48.                         */
  49.                         BufSize = ((PED->ped_MaxXDots + 15) / 16) * 2;
  50.             ColorSize = BufSize;
  51.             if (PD->pd_Preferences.PrintShade == SHADE_COLOR)
  52.                 BufSize *= 3;
  53.             colors[0] = ColorSize * 0; /* Black or yellow */
  54.             colors[1] = ColorSize * 1; /* Magenta */
  55.             colors[2] = ColorSize * 2; /* Cyan */
  56.                         PD->pd_PrintBuf = AllocMem(BufSize, MEMF_ANY);
  57.                         if (PD->pd_PrintBuf == NULL) {
  58.                                 err = PDERR_BUFFERMEMORY; /* no mem */
  59.                         }
  60.                         else if (OpenMyScrn(PED->ped_MaxXDots,
  61.                 PED->ped_MaxYDots) == NULL) {
  62.                     err = PDERR_BUFFERMEMORY;
  63.                 }
  64.                         break;
  65.  
  66.                 case 1 : /* Scale, Dither and Render */
  67.                         /*
  68.                                 ct      - pointer to PrtInfo structure.
  69.                                 x       - 0.
  70.                                 y       - row # (0 to Height - 1).
  71.                         */
  72.                         Transfer((struct PrtInfo *)ct, y, PD->pd_PrintBuf,
  73.                 colors);
  74.                         err = PDERR_NOERR; /* all ok */
  75.                         break;
  76.  
  77.                 case 2 : /* Dump Buffer to Printer */
  78.                         /*
  79.                                 ct      - 0.
  80.                                 x       - 0.
  81.                                 y       - # of rows sent (1 to NumRows).
  82.                         */
  83.             ptr=PD->pd_PrintBuf;
  84.             total=PD->pd_Preferences.PrintShade ==
  85.                 SHADE_COLOR ? 3 : 1;
  86.             for (i=0; i<total; i++) {
  87.                 CopyMem(ptr,planeptr[i],ColorSize);
  88.                 planeptr[i] +=
  89.                     myScrnHandle->BitMap.BytesPerRow;
  90.                 ptr += ColorSize;
  91.             };
  92.             linesleft--;
  93.                         break;
  94.  
  95.                 case 3 : /* Clear and Init Buffer */
  96.                         /*
  97.                                 ct      - 0.
  98.                                 x       - 0.
  99.                                 y       - 0.
  100.                         */
  101.                         ptr = PD->pd_PrintBuf;
  102.                         i = BufSize;
  103.                         do {
  104.                                 *ptr++ = 0;
  105.                         } while (--i);
  106.                         break;
  107.  
  108.                 case 4 : /* Close Down */
  109.                         /*
  110.                                 ct      - error code.
  111.                                 x       - io_Special flag from IODRPReq struct
  112.                                 y       - 0.
  113.                         */
  114.                         err = PDERR_NOERR; /* assume all ok */
  115.                         /* if user did not cancel the print */
  116.                         if (ct != PDERR_CANCEL) {
  117.                             /* if want to unload paper */
  118.                             if (!(x & SPECIAL_NOFORMFEED)) {
  119.                                 /* eject paper */
  120.                     Eject();
  121.                                 }
  122.                         }
  123.                         if (PD->pd_PrintBuf != NULL) {
  124.                                 FreeMem(PD->pd_PrintBuf, BufSize);
  125.                         }
  126.                         break;
  127.  
  128.                 case 5 : /* Pre-Master Initialization */
  129.                         /*
  130.                                 ct      - 0 or pointer to IODRPReq structure.
  131.                                 x       - io_Special flag from IODRPReq struct
  132.                                 y       - 0.
  133.                         */
  134.                         /* select density */
  135.                         SetDensity(x & SPECIAL_DENSITYMASK);
  136.                         break;
  137.         }
  138.         return(err);
  139. }
  140.  
  141. /* Open Screen File */
  142. int OpenMyScrn(ULONG w, ULONG h)
  143. {
  144.     static WORD scrnpal[9][4] = {
  145.         {0,-1,-1,-1},{1,-1,-1, 0},
  146.         {2,-1, 0,-1},{3,-1, 0, 0},
  147.         {4, 0,-1,-1},{5, 0,-1, 0},
  148.         {6, 0, 0,-1},{7, 0, 0, 0},
  149.         {-1,0,0,0}
  150.     };
  151.  
  152.     int i;
  153.     
  154.     if (myScrnHandle) {
  155.         if ((color_on) == (PD->pd_Preferences.PrintShade ==
  156.             SHADE_COLOR)) return TRUE;
  157.         else return FALSE;
  158.     }
  159.     if (color_on = (PD->pd_Preferences.PrintShade == SHADE_COLOR))
  160.         myScrnHandle=OpenScreenTags(NULL,
  161.             SA_Width,    w,
  162.             SA_Height,    h,
  163.             SA_Depth,    (ULONG)3,
  164.             SA_DisplayID,    (ULONG)0x8004,
  165.             SA_Colors,    scrnpal,
  166.             SA_AutoScroll,    (ULONG)TRUE,
  167.             SA_Quiet,    (ULONG)TRUE,
  168.             SA_Overscan,    (ULONG)OSCAN_STANDARD,
  169.             TAG_END);
  170.     else myScrnHandle=OpenScreenTags(NULL,
  171.         SA_Width,    w,
  172.         SA_Height,    h,
  173.         SA_Depth,    (ULONG)1,
  174.         SA_DisplayID,    (ULONG)0x8004,
  175.         SA_AutoScroll,    (ULONG)TRUE,
  176.         SA_Quiet,    (ULONG)TRUE,
  177.         SA_Overscan,    (ULONG)OSCAN_STANDARD,
  178.         TAG_END);
  179.     if(myScrnHandle==NULL) return FALSE;
  180.     linesleft = h;
  181.     for (i=0; i<3; i++) {
  182.         planeptr[i]=myScrnHandle->BitMap.Planes[i];
  183.     };
  184.     return TRUE;
  185. }
  186.     
  187. void Eject(void) {
  188.     if (myScrnHandle == NULL) return;
  189.  
  190.     CloseScreen(myScrnHandle);
  191.     myScrnHandle=NULL;
  192. }
  193.